<?php

namespace App\Models;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Tymon\JWTAuth\Contracts\JWTSubject;

class User extends Authenticatable implements JWTSubject
{
    use Notifiable;

    protected $table = 'ucenter_user_bind_connect';
    protected $primaryKey = 'bind_id';
    public $incrementing = false;
    protected $rememberTokenName = false;
    public $timestamps = false;
    protected $guarded = ['bind_id'];

    public static $bind_type = [
        'qq' => 2,
        'weixin' => 3,
        'aplipay' => 4,
        'mobile' => 12
    ];

    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    public function getJWTCustomClaims()
    {
        return [];
    }

    public function userInfo()
    {
        return $this->hasOne(UserInfo::class, 'user_id', 'user_id');
    }

    public function yfUserInfo()
    {
        return $this->hasOne(yfUserInfo::class, 'user_id', 'user_id');
    }

    public function userBase()
    {
        return $this->hasOne(UserBase::class, 'user_id', 'user_id');
    }

    public function userResource()
    {
        return $this->hasOne(UserResource::class, 'user_id', 'user_id');
    }

    public static function getByUserId(string $user_id) : User
    {
        return self::whereUserId($user_id)->first();
    }

    public static function getByMobile(string $mobile) : User
    {
        return self::find('mobile_' . $mobile);
    }

    public static function getByOpenid(string $openid) : User
    {
        return self::find('weixin_' . $openid);
    }
}
